Below is a program that calculates the average value of an array using Java.
public static void main(String[] args) { int[] arr= new int[]{1,2,3,4,5}; int sum = 0; for(int count=0; count < arr.length ; count++) sum = sum + arr[count]; double average = sum / arr.length; System.out.println("The average value of the array elements is : " + average); }
Happy Coding!
More Java Snippets
Convert Boolean Object to Boolean Primitive using Java
Get the sum of array element using Java
Get the square root of a number using Java
Comments